/***
 * 获取当前客户端位置信息
 */
import { WEB_APP_KEY } from '../config'
export const getLocationInfo = () => {
    return new Promise((resolve,reject) =>{
        fetch(`//restapi.amap.com/v3/ip?key=${WEB_APP_KEY}`)
            .then(res => {
                res.json().then(data => {
                    resolve(data)
                })
            }).catch(e =>{
                reject(e)
        })
    })
}
/***
 * @param origin { Array }
 * @param children { String }
 * @param key { String }
 * @param callBack  { function }
 * 遍历树，并为每个节点传入回调函数
 */
export const treeEach = (origin = [], children = 'children', key = 'id',callBack = () => {}) => {
    if(!Array.isArray(origin) || origin.length === 0) return
    for(let i = 0; i<origin.length;i++) {
        if(origin[i][children]) {
            treeEach(origin[i][children],children,key,callBack)
        } else {
            callBack(origin[i])
        }
    }
}
/**
 *  切换全屏显示
 */
export async function  toggleFullScreen() {
    if (!document.fullscreenElement) {
        // 进入全屏
        await document.documentElement.requestFullscreen();
    } else {
        // 退出全屏
        if (document.exitFullscreen) {
            await document.exitFullscreen();
        }
    }
}
